package com.easylinkin.linkappapi.lobar.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easylinkin.linkappapi.lobar.entity.WorkType;
import com.easylinkin.linkappapi.lobar.mapper.WorkTypeMapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @Author: kan yuanfeng
 * @Date: 2022/7/8 10:36
 * @Description: 劳务工具
 */
@Component
public class LobarUtils  implements ApplicationContextAware {
//  private static Map<String, String> workTypes = new HashMap<>();
  private static Map<String, String> natives = new HashMap<>();
  /**
   * 工种mapper
   */
  private static WorkTypeMapper workTypeMapper;
  static {

    //民族
    natives.put("汉族","1");natives.put("汉","1");
    natives.put("壮族","2");natives.put("壮","2");
    natives.put("满族","3");natives.put("满","3");
    natives.put("回族","4");natives.put("回","4");
    natives.put("苗族","5");natives.put("回","4");
    natives.put("维吾尔族","6");natives.put("维吾尔","6");
    natives.put("土家族","7");natives.put("土家","7");
    natives.put("彝族","8");natives.put("彝","8");
    natives.put("蒙古族","9");natives.put("蒙古","9");
    natives.put("藏族","10");natives.put("藏","10");
    natives.put("布依族", "11");natives.put("布依", "11");
    natives.put("侗族","12");natives.put("侗","12");
    natives.put("瑶族","13");natives.put("瑶","13");
    natives.put("朝鲜族","14");natives.put("朝鲜","14");
    natives.put("白族","15");natives.put("白","15");
    natives.put("哈尼族","16");natives.put("哈尼","16");
    natives.put("哈萨克族","17");natives.put("哈萨克","17");
    natives.put("黎族","18");natives.put("黎","18");
    natives.put("傣族","19");natives.put("傣","19");
    natives.put("畲族","20");natives.put("畲","20");
    natives.put("傈僳族","21");natives.put("傈僳","21");
    natives.put("仡佬族", "22");natives.put("仡佬", "22");
    natives.put("东乡族","23");natives.put("东乡","23");
    natives.put("高山族","24");natives.put("高山","24");
    natives.put("拉祜族","25");natives.put("拉祜","25");
    natives.put("水族","26");natives.put("水","26");
    natives.put("佤族","27");natives.put("佤","27");
    natives.put("纳西族","28");natives.put("纳西","28");
    natives.put("羌族","29");natives.put("羌","29");
    natives.put("土族","30");natives.put("土","30");
    natives.put("仫佬族","31");natives.put("仫佬","31");
    natives.put("锡伯族","32");natives.put("锡伯","32");
    natives.put("柯尔克孜族","33");natives.put("柯尔克孜","33");
    natives.put("达斡尔族","34");natives.put("达斡尔","34");
    natives.put("景颇族","35");natives.put("景颇","35");
    natives.put("毛南族","36");natives.put("毛南","36");
    natives.put("撒拉族","37");natives.put("撒拉","37");
    natives.put("布朗族","38");natives.put("布朗","38");
    natives.put("塔吉克族","39");natives.put("塔吉克","39");
    natives.put("阿昌族","40");natives.put("阿昌","40");
    natives.put("普米族","41");natives.put("普米","41");
    natives.put("鄂温克族","42");natives.put("鄂温克","42");
    natives.put("怒族","43");natives.put("怒","43");
    natives.put("京族","44");natives.put("京","44");
    natives.put("基诺族","45");natives.put("基诺","45");
    natives.put("德昂族","46");natives.put("德昂","46");
    natives.put("保安族","47");natives.put("保安","47");
    natives.put("俄罗斯族","48");natives.put("俄罗斯","48");
    natives.put("裕固族","49");natives.put("裕固","49");
    natives.put("乌孜别克族","50");natives.put("乌孜别克","50");
    natives.put("门巴族","51");natives.put("门巴","51");
    natives.put("鄂伦春族","52");natives.put("鄂伦春","52");
    natives.put("独龙族","53");natives.put("独龙","53");
    natives.put("塔塔尔族","54");natives.put("塔塔尔","54");
    natives.put("赫哲族","55");natives.put("赫哲","55");
    natives.put("珞巴族","56");natives.put("珞巴","56");
  }

  /**
   * 获取民族
   */
  public static String getNative(String key){
    return natives.get(key);
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    //设置工种缓存
    workTypeMapper = applicationContext.getBean(WorkTypeMapper.class);
  }

  /**
   * 获取工种
   * @return
   */
  public static Map<String, String> getWorkTypeMap(){
    //    //工种
//    LobarUtils.workTypes.put("总监理工程师","管理人员/总监理工程师");
//    LobarUtils.workTypes.put("副总监理工程师","管理人员/副总监理工程师");
//    LobarUtils.workTypes.put("安全监理工程师","管理人员/安全监理工程师");
//    LobarUtils.workTypes.put("专业监理工程师","管理人员/专业监理工程师");
//    LobarUtils.workTypes.put("监理工程师","管理人员/监理工程师");
//    LobarUtils.workTypes.put("监理员","管理人员/监理员");
//    LobarUtils.workTypes.put("监理安全员","管理人员/监理安全员");
//    LobarUtils.workTypes.put("项目总工程师","管理人员/项目总工程师");
//    LobarUtils.workTypes.put("项目经理","管理人员/项目经理");
//    LobarUtils.workTypes.put("工程经理","管理人员/工程经理");
//    LobarUtils.workTypes.put("项目技术负责人","管理人员/项目技术负责人");
//    LobarUtils.workTypes.put("项目工程师","管理人员/项目工程师");
//    LobarUtils.workTypes.put("施工员","管理人员/施工员");
//    LobarUtils.workTypes.put("质量员","管理人员/质量员");
//    LobarUtils.workTypes.put("安全员","管理人员/安全员");
//    LobarUtils.workTypes.put("标准员","管理人员/标准员");
//    LobarUtils.workTypes.put("材料员","管理人员/材料员");
//    LobarUtils.workTypes.put("机械员","管理人员/机械员");
//    LobarUtils.workTypes.put("劳务员","管理人员/劳务员");
//    LobarUtils.workTypes.put("资料员","管理人员/资料员");
//    LobarUtils.workTypes.put("测量员","管理人员/测量员");
//    LobarUtils.workTypes.put("实验员","管理人员/实验员");
//    LobarUtils.workTypes.put("造价员","管理人员/造价员");
//    LobarUtils.workTypes.put("项目总监","管理人员/项目总监");
//    LobarUtils.workTypes.put("生产经理","管理人员/生产经理");
//    LobarUtils.workTypes.put("项目管理员","管理人员/项目管理员");
//    LobarUtils.workTypes.put("安全负责人","管理人员/安全负责人");
////    workTypes.put("其他","管理人员/其他");
//
//    LobarUtils.workTypes.put("装载机司机","作业人员/特种作业人员/装载机司机");
//    LobarUtils.workTypes.put("挖掘机司机","作业人员/特种作业人员/挖掘机司机");
//    LobarUtils.workTypes.put("物联提升机司机","作业人员/特种作业人员/物料提升机司机");
//    LobarUtils.workTypes.put("施工升降机司机","作业人员/特种作业人员/施工升降机司机");
//    LobarUtils.workTypes.put("电焊工","作业人员/特种作业人员/电焊工");
//    LobarUtils.workTypes.put("建筑电工","作业人员/特种作业人员/建筑电工");
//    LobarUtils.workTypes.put("电工","作业人员/特种作业人员/电工");
//    LobarUtils.workTypes.put("木工","作业人员/普通作业人员/木工");
//    LobarUtils.workTypes.put("泥工","作业人员/普通作业人员/泥工");
//    LobarUtils.workTypes.put("钢筋工","作业人员/普通作业人员/钢筋工");
//    LobarUtils.workTypes.put("防水工","作业人员/普通作业人员/防水工");
//    LobarUtils.workTypes.put("砼工","作业人员/普通作业人员/砼工");
//    LobarUtils.workTypes.put("电焊工","作业人员/普通作业人员/电焊工");
//    LobarUtils.workTypes.put("水电工","作业人员/普通作业人员/水电工");
//    LobarUtils.workTypes.put("杂工","作业人员/普通作业人员/杂工");
//    LobarUtils.workTypes.put("架子工","作业人员/普通作业人员/架子工");
//    LobarUtils.workTypes.put("油漆工","作业人员/普通作业人员/油漆工");
//    LobarUtils.workTypes.put("其他","作业人员/普通作业人员/其他");
//
//
//    LobarUtils.workTypes.put("普通人员","其他人员/普通人员");
//    LobarUtils.workTypes.put("取样员","其他人员/取样员");
//    LobarUtils.workTypes.put("见证员","其他人员/见证员");
    Map<String, String> map = new HashMap<>();
    List<WorkType> workTypeList = workTypeMapper.selectList(new QueryWrapper<>());
    workTypeList.forEach(workType -> map.put(workType.getName(),workType.getFullName()));
    return map;
  }

  /**
   * 根据工种获取作业人员还是管理人员
   */
  public static boolean isManager(String workType){
    return StringUtils.isNotBlank(workType) && workType.startsWith("管理人员");
  }
}
